package basic.xiazheng;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/12 17:27
 * @描述 暂无
 */
public class Instanceofb {

    public static void main(String[] args) throws NoSuchFieldException {
        Animal animal = new Dog();
        System.out.println(animal.getClass());
        Animal a = new Animal();
        System.out.println(a.getClass());
        if (animal instanceof Dog) {
            animal.eat();
            Dog dog = (Dog) animal;
            dog.eat();
        }
        System.out.println(animal instanceof Cat);
//        Field field=animal.getClass().getField(animal.name);
        System.out.println(animal.getClass());


    }


    static class Cat extends Animal {
        @Override
        public void eat() {
            System.out.println("cat eat");
        }
    }

    static class Dog extends Animal {
        @Override
        public void eat() {
            System.out.println("dog eat");
        }
    }

    static class Animal {
        String name;

        Animal() {

        }

        public void eat() {
            System.out.println("eat!");
        }
    }
}
